package cnm.dao;

import org.hibernate.Criteria;
import org.hibernate.criterion.Order;

public class SorterHelper
{
	public static Order toOrder(Sorter sorter)
	{
		Order order;

		if (sorter.isAscending())
			order = Order.asc(sorter.getPropertyName());
		else
			order = Order.desc(sorter.getPropertyName());

		if (sorter.isIgnoreCase())
			order.ignoreCase();

		return order;
	}

	public static Criteria addSorter(Criteria criteria, Sorter sorter)
	{
		if (sorter == null)
			return criteria;

		return criteria.addOrder(toOrder(sorter));
	}
}
